package diko_parent.eduservice.controller.front;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.diko.commonUtils.R;
import diko_parent.eduservice.entity.EduCourse;
import diko_parent.eduservice.entity.Teacher;
import diko_parent.eduservice.service.EduChapterService;
import diko_parent.eduservice.service.EduCourseService;
import diko_parent.eduservice.service.TeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author Emma Li
 * @date 2020/10/13 - 20:19
 */
@RestController
//@CrossOrigin
@RequestMapping("/eduservice/index")
public class IndexController {
    @Autowired
    private EduCourseService chapterService;

    @Autowired
    private TeacherService teacherService;

    @GetMapping("index")
    public R index(){
        //查询前8条热门课程
        QueryWrapper<EduCourse> wrapper = new QueryWrapper<>();
        wrapper.orderByDesc("id");
        wrapper.last("limit 8");
        List<EduCourse> eduList = chapterService.list(wrapper);

        //查询前4条名师
        QueryWrapper<Teacher> wrapperTeacher = new QueryWrapper<>();
        wrapperTeacher.orderByDesc("id");
        wrapperTeacher.last("limit 4");
        List<Teacher> teacherList = teacherService.list(wrapperTeacher);

        return R.ok().data("eduList",eduList).data("teacherList",teacherList);
    }
}
